import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import "./assets/styles/base.less";
import "./assets/styles/el-reset.less";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import qfSubMenu from "qf-sub-menu";
import * as echarts from "echarts";
import bus from "./utils/bus";

//阿里图标symbel
let script = document.createElement("script");
script.src = "//at.alicdn.com/t/font_2691924_8mzike7r8nb.js";
document.documentElement.appendChild(script);

Vue.use(ElementUI);
Vue.use(qfSubMenu);
Vue.config.productionTip = false;
Vue.prototype.$echarts = echarts;
Vue.prototype.$bus = bus;

//用户菜单逻辑放这，防止刷新丢失

//导航守卫
//to目标路径 from原路径 ==>对象
//next 方法,相当于放行，组件才能渲染
//登入next（判断localStorage是否存入token） 未登入跳转登录页
// router.beforeEach((to, from, next) => {
//   let token = localStorage.getItem("token") || "";
//   if (!token) {
//     if (to.path === "/login") {
//       next();
//     } else {
//       next({ path: "/login" });
//     }
//   } else {
//     next();
//   }
// });

//全部后置钩子 处理面包屑
/* 没有next 已经进入页面不需要放行 */
//router.afterEach((to, from) => {
router.afterEach((to) => {
  var routerList = [...to.matched];
  store.commit("SET_CRUMBS", routerList);
  //第0项是空字符串，需要切掉,只是当前项目
  routerList.splice(0, 1); //第0项是空的，第一项里面有个name
});

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
